#include "myMain.h"

/* 配置 Config */
#define ANGLE_SOURCE_AS5047P 	0
#define ANGLE_SOURCE_CAN		1
#define ANGLE_SOURCE ANGLE_SOURCE_AS5047P		//角度位置来源

#define SHOOT_ENABLE			1				//推射使能
#define SHOOT_SET_ORIGIN_ENABLE	1				//推射上电设置原点使能
#define ORIGIN_CHEAK_CAN_ENABLE	0				//初始化时候是否检查几秒CAN连接

#define ENC_SPEED_ENABLE    	0 				//是否定时计算编码器速度

#define NORMAL 					sShootCMD.Duty 	
#define MODE5 					5
#define MODE10 					10
#define MODE50					50
#define MODE60					60
#define DEBUGMODE 				NORMAL   	//调试模式

#define cShootAngle				2700.f			//推射角度 2700

#define cCatchAngle				800.f			//运球接球的位置
#define cDeathZone				3.f				//死区

/***************/


#if ANGLE_SOURCE == ANGLE_SOURCE_AS5047P
	#include "AS5047P.h"
#elif ANGLE_SOURCE == ANGLE_SOURCE_CAN
	#include "AS5047P_CAN.h"
#endif

/* CAN数量定义 **********/

#define ENCNum	0
#if ANGLE_SOURCE == ANGLE_SOURCE_CAN
	#undef ENCNum
	#define ENCNum	1
#endif

#define VESCNum 5
#define DMNum 	4
#define DJINum 	2
#define CANNum (VESCNum + DMNum + DJINum + ENCNum)

/* 电机数量定义↑↑↑↑↑*/

extern VESC_HandleTypeDef WheelLB;     //轮电机
extern VESC_HandleTypeDef WheelRB;
extern VESC_HandleTypeDef WheelRF;
extern VESC_HandleTypeDef WheelLF;
extern DJI_HandleTypeDef HelmLB;        //舵电机
extern DJI_HandleTypeDef HelmRB;
extern DJI_HandleTypeDef HelmRF;
extern DJI_HandleTypeDef HelmLF;
#define WheelLBID 54
#define WheelRBID 53
#define WheelRFID 52
#define WheelLFID 51
#define HelmLBID  4
#define HelmRBID  3
#define HelmRFID  2
#define HelmLFID  1

extern VESC_HandleTypeDef Shoot;     //推射电机
#define ShootID	40

extern DJI_HandleTypeDef Defense;
#define DefenseID   5
extern DJI_HandleTypeDef NetL;
extern DJI_HandleTypeDef NetR;
#define NetLID   1
#define NetRID   2

extern uint8_t NetLRxFlag;
extern uint8_t NetRRxFlag;

extern uint16_t IDArray[CANNum];
extern uint8_t IDFlagArray[CANNum];

/* 推射相关变量 */
extern float gShootNowAngle;

/* 编码器相关参数定义 */

extern float gShootLastAngle;
extern float gShootReadAngle;
extern float gShootNowAngle_buff;

#if ANGLE_SOURCE == ANGLE_SOURCE_AS5047P
extern AS5047P_HandleTypeDef shootEnc;
#elif ANGLE_SOURCE == ANGLE_SOURCE_CAN

#endif
extern WS2811_HandleTypeDef LEDStrip;

/* 离合刹车宏定义 */
#define clutchUnBreak() 		HAL_GPIO_WritePin(shootBreak_GPIO_Port, shootBreak_Pin, GPIO_PIN_RESET) 	/* 离合器取消刹车 */
#define clutchBreak() 			HAL_GPIO_WritePin(shootBreak_GPIO_Port, shootBreak_Pin, GPIO_PIN_SET);		/* 离合器刹车 */

#if ENC_SPEED_ENABLE
extern volatile float gShootSpeed;
#endif

extern volatile struct myErrState gErrState;
extern volatile bool gMotorRxInitFinishFlag;
extern volatile bool gMechInitFinishAndStartEncFlag;
extern volatile bool gMechInitFinishAndInFreeRTOSFlag;
extern volatile bool gMotorONFlag;
extern volatile uint8_t gMechInitMode;

void deviceInit();
void mechInit();
void communicateInit();

